package cn._51doit.flink.day01.sources;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FlinkParallelism {

    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //获取执行环境的并行度：
        //如果是本地模式，默认的并行度与机器的逻辑核数一致 （Runtime.getRuntime().availableProcessors();）
        //如果是集群模式，默认的并行度与提交任务时指定的参数 -p 一致
        int parallelism = env.getParallelism();

        System.out.println("程序执行环境的并行度：" + parallelism);
        //调用socketTextStream方法创建的DataStream并行度永远都是1，nc-lk不支持多个消费者同时从一个端口中读取数据
        //所以读数据的效率会比较低，该Source只用来做实验，不用于生产环境
        DataStreamSource<String> lines = env.socketTextStream("localhost", 8888);

        int sourceParallelism = lines.getParallelism();

        System.out.println("Source的并行度为：" + sourceParallelism);


    }

}
